var app = getApp()
var host = app.data.host
var httpUtil = require("../utils/httpUtil.js")
var addQuanUrl = host + "addCustomerQuan"
var getCustomerQuanUrl = host + "getCustomerQuan"
var getQuanInfoUrl = host + "getQuanInfo"
var getCustomerQuanRoleUrl = host + 'getCustomerQuanRole'
//用户领取优惠券
function addQuan(data, cb) {
  var user = app.data.user
  data.cusId = user.id
  data.cusName = user.name
  httpUtil.post(addQuanUrl, data, cb)
}
//获取用户所有可用优惠券
function getAllQuan(cb) {
  var data = {
    cusId: app.data.user.id
  }
  httpUtil.get(getCustomerQuanUrl, data, cb)
}
//获取优惠券信息
function getQuanInfo(id, cb) {
  var data = {
    quanId: id
  }
  httpUtil.get(getQuanInfoUrl, data, cb)
}
//获取指定优惠券领取权限
function getCustomerQuanRole(id, cb) {
  var data = {
    cusId:app.data.user.id,
    quanId:id
  }
  httpUtil.post(getCustomerQuanRoleUrl, data, cb)
}
module.exports = {
  addQuan: addQuan,
  getAllQuan: getAllQuan,
  getQuanInfo: getQuanInfo,
  getCustomerQuanRole: getCustomerQuanRole
}